package com.example.demo.itemReader.itemReadeFromFile.outPutdata;

import java.sql.Date;
import java.util.Calendar;
import java.util.Random;

public class Customer {
    private long id;
    private String firstName;
    private String lastName;
    private String birthday;

    @Override
    public String toString() {
        return  id + "," + firstName+ "," + lastName + ", " + birthday ;
    }

    public long getId() { return id; }
    public void setId(long id) { this.id = id; }
    public String getFirstName() {return firstName; }
    public void setFirstName(String firstName) {this.firstName = firstName; }
    public String getLastName() { return lastName; }
    public void setLastName(String lastName) { this.lastName = lastName; }
    public String getBirthday() { return birthday; }
    public void setBirthday(String birthday) { this.birthday = birthday; }
    public Customer(){}

    public Customer(long id, String firstName, String lastName, String birthday) {
        this.id = id;
        this.firstName = firstName;
        this.lastName = lastName;
        this.birthday = birthday;
    }
    public Customer(long id){
        this.id=id;
        this.firstName = randomFirstName();
        this.lastName = randomLastName();
        this.birthday = randomDate();

    }

    private  String randomFirstName() {
        int min = 5;
        int max = 10;
        String name;
        char[] nameChar;
        //名字最长为max个,最短为min个
        int nameLength=(int)(Math.random()*(max-min+1))+min;
        nameChar=new char[nameLength];
        //生成大写首字母
        nameChar[0]=(char) (Math.random()*26+65);
        for(int i=1;i<nameLength;i++) {
            nameChar[i]=(char)(Math.random()*26+97);
        }
        name=new String(nameChar);
        return name;

    }
    private  String randomLastName() {
        int min = 5;
        int max = 10;
        String name;
        char[] nameChar;
        //名字最长为max个,最短为min个
        int nameLength=(int)(Math.random()*(max-min+1))+min;
        nameChar=new char[nameLength];
        //生成大写首字母
        nameChar[0]=(char) (Math.random()*26+65);
        for(int i=1;i<nameLength;i++) {
            nameChar[i]=(char)(Math.random()*26+97);
        }
        name=new String(nameChar);
        return name;

    }
    public  Date randomBirthday() {
        int startYear=2016;
        int endYear=2018;
        int year = (int)(Math.random()*(endYear-startYear+1))+startYear;	//随机年
        int month= (int)(Math.random()*12)+1;								//随机月
        Calendar c = Calendar.getInstance();				//创建Calendar对象
        c.set(year, month, 0);								//设定日期
        int dayOfMonth = c.get(Calendar.DAY_OF_MONTH);		//获取对应年月有几天
        int day=(int)(Math.random()*dayOfMonth+1)	;		//产生随机日
        Date birthday= Date.valueOf(year+"-"+month+"-"+day);	//通过valueOf方法生成Date对象
        return birthday;
    }
    private String randomDate(){
        Random rndYear=new Random();
        int year=rndYear.nextInt(18)+2000;
        Random rndMonth=new Random();
        int month=rndMonth.nextInt(12)+1;
        Random rndDay=new Random();
        int Day=rndDay.nextInt(30)+1;
        Random rndHour=new Random();
        int hour=rndHour.nextInt(23);
        Random rndMinute=new Random();
        int minute=rndMinute.nextInt(60);
        Random rndSecond=new Random();
        int second=rndSecond.nextInt(60);
        return year+"-"+cp(month)+"-"+cp(Day)+"  "+cp(hour)+":"+cp(minute)+":"+cp(second);
    }
    private String cp(int num){
        String Num=num+"";
        if (Num.length()==1){
            return "0"+Num;
        }else {
            return Num;
        }
    }
}

